#include "LuaCommands.h"

//lua "game.state" functions
static const luaL_reg statesFunc[] = {
	{"addState",addState},
	{"registerLoadFunc",registerLoadFunc},
	{"registerLoopFunc",registerLoopFunc},
	{"registerMouseButtonDownFunc",registerMouseButtonDownFunc},
	{"registerMouseButtonReleasedFunc",registerMouseButtonReleasedFunc},
	{"registerKeyboardKeyDownFunc", registerKeyboardKeyDownFunc},
	{"registerKeyboardKeyReleasedFunc", registerKeyboardKeyReleasedFunc},
	{"setActiveState",setActiveState},
	{NULL,NULL}
};

void registerCommands_luaStates(lua_State* L){
	luaL_register(L, "game.state",statesFunc);
	/*lua_pushvalue(L,-1);
 	lua_setfield(L, -2, "__index"); */ 
}

//lua "game.images" functions
static const luaL_reg imagesFunc[] = {
	{"load",loadImage},
	{"drawPos",drawPosImage},
	{"drawPosSub",drawPosSubImage},
	{"draw",drawImage},
	{"drawSub",drawSubImage},
	{"setPos",setPosImage},
	{"getSize",getSizeImage},
	{"resize",resizeImage},
	{"isMouseOver", isMouseOverImage},
	{NULL,NULL}
};

void registerCommands_luaImages(lua_State* L){
	luaL_newmetatable(L, "Data.Image");
    luaL_register(L, 0, imagesFunc);            
    lua_pushvalue(L,-1);
    lua_setfield(L,-2, "__index");  

	luaL_register(L, "game.images", imagesFunc);
}

//lua "game.font" functions
static const luaL_reg fontFunc[] = {
	{"create",createFont},
	{"draw",drawFont},
	{"setSize",setSizeFont},
	{"setFrontColor", setFrontColorFont},
	{"setBackColor", setBackColorFont},
	{"destroy", destroyFont},
	{NULL,NULL}
};

void registerCommands_luaFont(lua_State* L){
	luaL_newmetatable(L, "Data.Font");
    luaL_register(L, 0, fontFunc);
    lua_pushvalue(L,-1);
    lua_setfield(L,-2, "__index");

	luaL_register(L, "game.font", fontFunc);
}

//lua "game.mouse" functions
static const luaL_reg mouseFunc[] = {
	{"getPosition",getPositionMouse},
	{"getRelativePosition",getRelativePositionMouse},
//	{"getX",getX},
//	{"getY",getY},
	{"isDown",isDownMouse},
	{"setPosition",setPositionMouse},
	{"setVisible",setVisibleMouse},
	{"isVisible", isVisibleMouse},
	{NULL,NULL}
};

void registerCommands_luaMouse(lua_State* L){
	luaL_register(L, "game.mouse",mouseFunc);
}

//lua "game" functions
static const luaL_reg gameFunc[] = {
	{"quit",quitGame},
	{NULL,NULL}
};

void registerCommands_luaGame(lua_State* L){
	luaL_register(L, "game",gameFunc);
}

static const luaL_reg pixmapFunc[] = {
	{"load",loadPixmap},
	{"draw", drawPixmap},
	{"drawPos",drawPixmapPos},
	{"setPixel", setPixelPixmap},
	{"getPixel", getPixelPixmap},
	{"delet", deletePixmap},
	{NULL,NULL}
};

void registerCommands_luaPixmap(lua_State* L){
	luaL_newmetatable(L, "Data.Pixmap");
    luaL_register(L, 0, fontFunc);
    lua_pushvalue(L,-1);
    lua_setfield(L,-2, "__index");

	luaL_register(L, "game.pixmap", pixmapFunc);
}
